package com.youlai.boot.word.controller;

import com.youlai.boot.common.result.Result;
import com.youlai.boot.word.entity.QueryForm;
import com.youlai.boot.word.service.WordListMongoInterface;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController()
@RequestMapping("/word")
public class WordController {

    private final static String collection = "word";

    @Autowired
    private WordListMongoInterface wordListMongoInterface;

    @GetMapping("/list")
    public Result<?> getList(){
        List<?> word = wordListMongoInterface.getAllListData(collection);
        if(word.isEmpty()){
            return Result.failed("未查询到数据");
        }
        return Result.success(word);
    }

    @GetMapping("listPage")
    public Result<?> getListPage(@RequestBody QueryForm queryForm){
        List<?> dataByPage = wordListMongoInterface.getAllListDataByPage(collection, queryForm);
        if(dataByPage.isEmpty()){
            return Result.failed("未查询到数据");
        }
        return Result.success(dataByPage);
    }
}
